package vip.zhenzicheng.nettybasic.serializable.msgpack;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.msgpack.MessagePack;

/**
 * 基于MessagePack的编码器，序列化
 *
 * @author zhenzicheng
 * @date 2022-06-27 15:54
 */
public class MsgPackEncode extends MessageToByteEncoder<User> {
  @Override
  protected void encode(ChannelHandlerContext ctx, User msg, ByteBuf out) throws Exception {
    MessagePack messagePack = new MessagePack();
    byte[] raw = messagePack.write(msg);
    out.writeBytes(raw);

  }
}
